package com.lin.fengxiu.api.v1;

import com.lin.fengxiu.exception.http.NotFoundException;
import com.lin.fengxiu.model.Category;
import com.lin.fengxiu.model.GridCategory;
import com.lin.fengxiu.service.CategoryService;
import com.lin.fengxiu.service.GridCategoryService;
import com.lin.fengxiu.vo.CategoriesAllVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName CategoryController
 * @Description TODO
 * @Author wushaopei
 * @Date 2021/3/16 23:19
 * @Version 1.0
 */
@RequestMapping("category")
@RestController
@ResponseBody
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private GridCategoryService gridCategoryService;

    @GetMapping("/all")
    public CategoriesAllVO getAll(){
        Map<Integer,List<Category>> categorys = categoryService.getAll();
        return new CategoriesAllVO(categorys);
    }

    @GetMapping("/grid/all")
    public List<GridCategory> getGridCategoryList(){
        List<GridCategory> gridCategories = gridCategoryService.getGridCategoryList();
        if(gridCategories.isEmpty()){
            throw new NotFoundException(30009);
        }
        return gridCategories;
    }
}
